﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;

namespace TaxonomyServiceTest
{
    public partial class Form1 : Form
    {
        private static string websiteUrl = "http://localhost/TaxonomySite";
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSetTerm_Click(object sender, EventArgs e)
        {
            try
            {
                //Set up proxy
                BasicHttpBinding binding = new BasicHttpBinding();
                binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
                EndpointAddress endpoint = new EndpointAddress(websiteUrl + "/_vti_bin/TaxonomyService/Taxonomyservice.svc");
                TaxonomyServiceRef.TaxonomyServiceClient proxy = new TaxonomyServiceRef.TaxonomyServiceClient(binding, endpoint);
                proxy.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

                //Call web service
                Boolean result = proxy.SetTaxonomy(txtDocumentName.Text, txtTermValue.Text);

                if (result)
                {
                    MessageBox.Show("Set term successfully!");
                }
                else
                {
                    MessageBox.Show("Failed to set term!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
